// pages/collect/index.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    collect:[],
    tabs: [
      {
        id: 0,
        name: "商品收藏",
        isactive: true
      },
      {
        id: 1,
        name: "品牌收藏",
        isactive: false
      },
      {
        id: 2,
        name: "店铺收藏",
        isactive: false
      },
      {
        id: 3,
        name: "浏览足迹",
        isactive: false
      }
    ]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },
  onShow(){
    //拿到收藏商品数组
    const collect = wx.getStorageSync('collect');
    this.setData({
      collect
    })
  },
  handletabsClick(e) {
    // 获取传过来的索引
    const { index } = e.detail
    //修改原数组
    let { tabs } = this.data
    tabs.forEach(item => {
      if (item.id === index) {
        item.isactive = true
      } else {
        item.isactive = false
      }
    })
    //重新赋值tabs
    this.setData({
      tabs
    })
  }

})